<?php
elseif ($_REQUEST['act'] == 'export_visitor')
{
    $html = '';
    include_once (ROOT_PATH . 'include/vendor/PHPExcel.php');
    include_once (ROOT_PATH . 'include/vendor/PHPExcel/IOFactory.php');
    //require_once dirname(__FILE__) . '/Classes/PHPExcel.php';
    //require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';
    $PHPExcel = new PHPExcel();

    //设置excel属性基本信息
    $PHPExcel->getProperties()->setCreator("Neo")
        ->setLastModifiedBy("Neo")
        ->setTitle("111")
        ->setSubject("访客列表")
        ->setDescription("")
        ->setKeywords("访客列表")
        ->setCategory("");
    $PHPExcel->setActiveSheetIndex(0);
    $PHPExcel->getActiveSheet()->setTitle("访客列表");
    //填入表头主标题
    $PHPExcel->getActiveSheet()->setCellValue('A1', $_CFG['shop_name'].'访客列表');
    //填入表头副标题
    $PHPExcel->getActiveSheet()->setCellValue('A2', '操作者：'.$_SESSION['admin_name'].' 导出日期：'.date('Y-m-d',time()).' 地址：'.$_CFG['shop_address'].' 电话：'.$_CFG['service_phone']);
    //合并表头单元格
    $PHPExcel->getActiveSheet()->mergeCells('A1:F1');
    $PHPExcel->getActiveSheet()->mergeCells('A2:F2');

    //设置表头行高
    $PHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(40);
    $PHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
    $PHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(30);

    //设置表头字体
    $PHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
    $PHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
    $PHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $PHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setName('宋体');
    $PHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
    $PHPExcel->getActiveSheet()->getStyle('A3:F3')->getFont()->setBold(true);

    //设置单元格边框
    $styleArray = array(
        'borders' => array(
            'allborders' => array(
                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
                'style' => PHPExcel_Style_Border::BORDER_THIN,//细边框
                //'color' => array('argb' => 'FFFF0000'),
            ),
        ),
    );

    //表格宽度
    $PHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(30);//订单编号
    $PHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);//创建时间
    $PHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);//买家信息
    $PHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(30);//推客信息
    $PHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);//收货信息
    $PHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);//订单实付款
//    $PHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(30);//订单流水号
//    $PHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);//物流单号
//    $PHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(30);//订单状态

    //表格标题
    $PHPExcel->getActiveSheet()->setCellValue('A3', '访客ID');
    $PHPExcel->getActiveSheet()->setCellValue('B3', '推客信息');
    $PHPExcel->getActiveSheet()->setCellValue('C3', '注册时间');
    $PHPExcel->getActiveSheet()->setCellValue('D3', '累积订单数');
    $PHPExcel->getActiveSheet()->setCellValue('E3', '累积消费额');
    $PHPExcel->getActiveSheet()->setCellValue('F3', '平均消费额');
//    $PHPExcel->getActiveSheet()->setCellValue('G3', '订单流水号');
//    $PHPExcel->getActiveSheet()->setCellValue('H3', '物流单号');
//    $PHPExcel->getActiveSheet()->setCellValue('I3', '订单状态');

    $hang = 4;
    $visitor_list = visitor_list(-1);
    foreach ($visitor_list['visitor_list'] as $k=>$v){
        $v['drp_info'] = '推客ID：'.$v['parent_name']."\n".'分销商ID：'.$v['reseller_name'];
        $PHPExcel->getActiveSheet()->setCellValue('A' . ($hang), $v['user_name']." ");//访客
        $PHPExcel->getActiveSheet()->setCellValue('B' . ($hang), $v['drp_info']);//推客消息
        $PHPExcel->getActiveSheet()->setCellValue('C' . ($hang), $v['reg_time']);//注册时间
        $PHPExcel->getActiveSheet()->setCellValue('D' . ($hang), $v['order_count']);//累积订单数
        $PHPExcel->getActiveSheet()->setCellValue('E' . ($hang), $v['money_account']);//累积消费额
        $PHPExcel->getActiveSheet()->setCellValue('F' . ($hang), $v['money_avg']);//平均消费额

        $hang = $hang+1;
    }

    //设置单元格边框
    $PHPExcel->getActiveSheet()->getStyle('A1:F'.$hang)->applyFromArray($styleArray);
    //设置自动换行
    $PHPExcel->getActiveSheet()->getStyle('A4:F'.$hang)->getAlignment()->setWrapText(true);
    //设置字体大小
    $PHPExcel->getActiveSheet()->getStyle('A4:F'.$hang)->getFont()->setSize(12);
    //垂直居中
    $PHPExcel->getActiveSheet()->getStyle('A1:F'.$hang)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    //水平居中
    $PHPExcel->getActiveSheet()->getStyle('A1:F'.$hang)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//    $PHPExcel->getActiveSheet()->getStyle('C4:E'.$hang)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="visitor_'.date('Y-m-d').'.xls"');
    header('Cache-Control: max-age=0');
    $Writer = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
    $Writer->save("php://output");
    exit;
}
?>